#!/bin/sh
base=$(cd `dirname $0`; pwd)
base=$(echo $base | awk -F /artifacts '{print $1}')

# GR lib
for ff in $base/lib/*.jar
do
    path=$ff:$path
done

EIUM_HOME=`grep EIUM_HOME $base/conf/grm.properties | awk -F= '{print $2}'`

# eIUM lib
for ff in $EIUM_HOME/lib/*.jar
do
    if [[ "$ff" != "$EIUM_HOME/lib/slf4j-api.jar" && "$ff" != "$EIUM_HOME/lib/siulogging-slf4j.jar" ]]
    then
        path="$ff:$path"
    fi
done

# eIUM plugins: latest com.hp.usage.jmx_x.y.z
PLUGINS_JMX=`ls $EIUM_HOME/plugins -r | grep com.hp.usage.jmx_ | head -1`
path="$EIUM_HOME/plugins/$PLUGINS_JMX/jdmkrt.jar:$EIUM_HOME/plugins/$PLUGINS_JMX/jmx.jar:$path"
taskname=$1
parameter=$2
fileName=`echo "SNAP-GR-SMAN-Tools.sh $1" |md5sum | cut -d' ' -f1`
nohup java -DGRHome=$base -Dlogback.configurationFile=file://$base/conf/logback.xml -classpath $path com.hp.snap.gr.GRMLauncher GRSITE $taskname $fileName $parameter >$base/temp/${fileName}.out 2>&1 &
echo "${fileName}"